<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../baseAdm.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns="http://www.w3.org/1999/xhtml">
    
    <f:metadata>
        <f:viewParam name="id" value="#{contratoFace.selectedCliente}"/>
    </f:metadata>
    
    <ui:define name="content">
        
        
        <h:form id="form" ><p:growl id="growl" showDetail="true" showSummary="true" />
            <p:ajaxStatus style="width:16px;height:16px;">
                <f:facet name="start">
                    <h:graphicImage name="ajaxloading.gif" library="images" />
                </f:facet>

                <f:facet name="complete">
                    <h:outputText value="" />
                </f:facet>
            </p:ajaxStatus>
            
            <p:dataTable id="tabela" var="varTabela" value="#{contratoFace.lista}"
                         selectionMode="single" resizableColumns="true" scrollable="true" scrollWidth="300"
                         ><!--
                <f:facet name="header">
                    <h:outputText value="Contratos de Demanda de #{contratoFace.selectedCliente.nickName}"/>
                </f:facet>-->
                <p:column headerText="Id" footerText="Id"  style="width: 100px">
                    <h:outputText value="#{varTabela.id}"/>
                </p:column>

                <p:column headerText="Início Vigência" footerText="Início Vigência" style="width: 100px">
                    <h:outputText value="#{varTabela.inicio}">
                        <f:convertDateTime timeZone="pt_BR"/>
                    </h:outputText>
                </p:column>
                
                
                <p:column headerText="Tarifa" footerText="Tarifa" style="width: 100px">
                    <h:outputText value="#{varTabela.tarifa.tipoTarifa.descricao}"/>
                </p:column>

                <p:column headerText="Janeiro FP" footerText="Janeiro FP" style="width: 100px">
                    <h:outputText value="#{varTabela.janFp}"/>
                </p:column>
                <!--
                <p:column headerText="Fevereiro FP" style="text-align: center">
                    <h:outputText value="#{varTabela.fevFp}"/>
                </p:column>
                <p:column headerText="Março FP" style="text-align: center">
                    <h:outputText value="#{varTabela.marFp}"/>
                </p:column>
                <p:column headerText="Abril FP" style="text-align: center">
                    <h:outputText value="#{varTabela.abrFp}"/>
                </p:column>
                <p:column headerText="Maio FP" style="text-align: center">
                    <h:outputText value="#{varTabela.maiFp}" />
                </p:column>
                <p:column headerText="Junho FP"  style="text-align: center">
                    <h:outputText value="#{varTabela.junFp}"/>
                </p:column>
                
                <p:column headerText="Julho FP" style="text-align: center">
                    <h:outputText value="#{varTabela.julFp}"/>
                </p:column>
                
                <p:column headerText="Agosto FP" style="text-align: center">
                    <h:outputText value="#{varTabela.agoFp}"/>
                </p:column>
                <p:column headerText="Setembro FP" style="text-align: center">
                    <h:outputText value="#{varTabela.setFp}"/>
                </p:column>
                <p:column headerText="Outubro FP" style="text-align: center">
                    <f:facet name="header">Outubro FP</f:facet>
                    <h:outputText value="#{varTabela.outFp}"/>
                </p:column>
                <p:column headerText="Novembro FP" style="text-align: center">
                    <h:outputText value="#{varTabela.novFp}"/>
                </p:column>
                <p:column headerText="Dezembro FP" style="text-align: center">
                    <h:outputText value="#{varTabela.dezFp}"/>
                </p:column>

                

                <p:column headerText="Ações" style="text-align: center;width: 80px">
                    <p:commandButton image="ui-icon-pencil" update=":form:painel"
                                     oncomplete="conceDialog.show()" title="Editar" >
                        <f:setPropertyActionListener value="#{varTabela}" target="#{contratoFace.selectedBean}" />
                    </p:commandButton>

                    <p:commandButton image="ui-icon-trash" update="painel"
                                     title="Excluir" oncomplete="confirmation.show()" >
                        <f:setPropertyActionListener value="#{varTabela}" target="#{contratoFace.selectedBean}" />
                    </p:commandButton>
                    
                </p:column>
                -->
                <f:facet name="footer">
                    <p:commandButton image="ui-icon-disk" update=":form:painel"
                                     title="Novo" value="Novo" oncomplete="conceDialog.show()"
                                     action="#{contratoFace.doCreate}"/>
                </f:facet>
                

            </p:dataTable>

            <!--  Tela de edição / Inclusão
            -->
            
            <p:dialog widgetVar="conceDialog" width="500" resizable="false" modal="true"
                      id="conceDlg" header="Cadastro de tabelasionárias" showEffect="explode"
                      hideEffect="slide" >
                <p:outputPanel id="painel" >
                    <script type="text/javascript">
                        (function($){
                            $(function(){
                                $('input:text').setMask();
                            });
                        })(jQuery);

                    </script>
                    
                    <h:panelGrid columns="4"  >
                        <h:outputLabel value="Concessionária:" />
                        <h:selectOneMenu  value="#{contratoFace.selectedConce}" converter="conceConverter" 
                                          rendered="true" >
                            <f:selectItems   value="#{icmsFace.listaConce}" var="cbConce"
                                             itemLabel="#{cbConce.abrev}" itemValue="#{cbConce}" />
                            <f:ajax render="cbTarifa"/>
                        </h:selectOneMenu>
                        
                        <h:outputLabel value="Tarifa:" />
                        <h:selectOneMenu  value="#{contratoFace.selectedBean.tarifa}" converter="tarifaConverter"
                                          rendered="true" id="cbTarifa">
                            <f:selectItems   value="#{contratoFace.listaTarifa}" var="cbTipoTar"
                                             itemLabel="#{cbTipoTar.tipoTarifa.descricao}" itemValue="#{cbTipoTar}" />
                            <f:ajax render="demFP"/>
                            
                        </h:selectOneMenu>
                        
                        <h:outputLabel value="Tipo de Uso" />
                        <h:selectOneMenu  value="#{contratoFace.selectedBean.tipoUso}" converter="tipoUsoConverter" 
                                          rendered="true" >
                            <f:selectItems   value="#{icmsFace.listaT}" var="cbTipoUso"
                                             itemLabel="#{cbTipoUso.descricao}" itemValue="#{cbTipoUso}" />
                            
                        </h:selectOneMenu>
                        <h:outputLabel value="Início:"/>
                        <p:calendar value="#{contratoFace.selectedBean.inicio}"/>
                    </h:panelGrid>
                    <p:panel header="Demanda Fora Ponta" id="demFP" >
                        <h:panelGrid columns="6" rendered="#{cbTipoUso.id != 4}"  >
                            <h:outputLabel value="Janeiro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.janFp}" alt="integer9" size="5" />

                            <h:outputLabel value="Fevereiro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.fevFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Março:"/>
                            <p:inputText value="#{contratoFace.selectedBean.marFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Abril:"/>
                            <p:inputText value="#{contratoFace.selectedBean.abrFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Maio:"/>
                            <p:inputText value="#{contratoFace.selectedBean.maiFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Junho:"/>
                            <p:inputText value="#{contratoFace.selectedBean.junFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Julho:"/>
                            <p:inputText value="#{contratoFace.selectedBean.julFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Agosto:"/>
                            <p:inputText value="#{contratoFace.selectedBean.agoFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Setembro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.setFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Outubro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.outFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Novembro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.novFp}" alt="integer9" size="5"/>
                            
                            <h:outputLabel value="Dezembro:"/>
                            <p:inputText value="#{contratoFace.selectedBean.dezFp}" alt="integer9" size="5"/>
                        </h:panelGrid>
                    </p:panel>
                    
                    <h:panelGrid columns="2">
                        <p:commandButton value="Salvar" action="#{contratoFace.doSave()}"
                                         oncomplete="conceDialog.hide()" update="tabela">

                        </p:commandButton>
                        <p:commandButton value="Cancelar" oncomplete="conceDialog.hide()" action="#{contratoFace.resetIsNew}"/>
                    </h:panelGrid>

                </p:outputPanel>
            </p:dialog>

            <p:confirmDialog message="Você deseja realmente exluir este registro?" width="200"
                             header="Confirmação" severity="alert" widgetVar="confirmation">

                <p:commandButton value="Sim" update="tabela" action="#{contratoFace.doRemove}"
                                 oncomplete="confirmation.hide()"/>
                <p:commandButton value="Não" onclick="confirmation.hide()" type="button" />

            </p:confirmDialog>
        </h:form>

    </ui:define>

</ui:composition>